package Jets.animate
{
	import flash.display.MovieClip;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class JAnimateMC extends JAnimateBase
	{
		/**
		 * 时间线对象 
		 */
		public var timeLine:JTimeLine;
		
		private var ms_nMovieClip:MovieClip = null;
		public function JAnimateMC(mc:MovieClip=null,paused:Boolean=false)
		{
			super(mc,paused);
			
		}
		
		/**
		 * 获得当前动画 
		 * @return 
		 * 
		 */
		public function get mc():MovieClip
		{
			return ms_nMovieClip;
		}
		
		public override function get curLabelName():String
		{
			return timeLine.curLabelName;
		}

		public override function getLabelIndex(labelName:String):int
		{
			return timeLine.getLabelIndex(labelName);
		}

		public override function get labels():Array
		{
			return timeLine && enabledLabelMovie ? timeLine.labels : null;
		}

		public override function set labels(value:Array):void
		{
			if (timeLine)
				timeLine.labels = value;
		}
		

		public override function set currentFrame(frame:int):void
		{
			if (frame < 1)
				frame = 1;
			if (frame > totalFrames)
				frame = totalFrames;
			
			if (currentFrame == frame)
				return;
			
			if (mc)
			{
				if (frame == currentFrame + 1) 
					mc.nextFrame();
				else if (frame == currentFrame - 1)
					mc.prevFrame();
				else
					mc.gotoAndStop(frame);
			}
			super.currentFrame = frame;
		}

		public override function get totalFrames():int
		{
			return timeLine ? timeLine.totalFrames : 0;
		}
		
		/**
		 * 将动画缓存为位图并转化为JAnimateBitmaps对象
		 * 注意这个缓存是需要时间的，如果要在完全生成JAnimateBitmaps对象后进行一些操作，可监听JAnimateBitmaps的complete事件
		 * 
		 * @param rect		绘制范围
		 * @param start		起始帧
		 * @param len		长度
		 * @param readWhenPlaying	是否立即显示
		 * @param limitTimeInFrame	每次缓存允许的最高时间
		 * 
		 * @return 
		 * 
		 */
		public static function toJAnimateBitmaps(mc:MovieClip,rect:Point=null,offest:Point=null,start:int = 1,len:int = -1,readWhenPlaying:Boolean = false,limitTimeInFrame:int = 10):JAnimateBitmaps
		{
			var v:JAnimateBitmaps = new JAnimateBitmaps();
			v.createFromMovieClip(mc,rect,offest,start,len);
			return v;
		}
	}
}